<template>
  <v-table :hasEdit="false"
           :page="page"
           :pageSize="pageSize"
           :tableConfig="tableConfig"
           :tableData="tableData"
           :total="total"
           @findData="getTableData"
           @getTableData="getTableData"
           @searhData="setSearhData"
           @selectData="setSelectData"
           @upData="getTableData"
           ref="table"></v-table>
</template>

<script>
import table from 'commons/Table'
import baseMixin from "@/mixins/BaseMixin";

export default {
  name: "Table",
  mixins: [baseMixin],
  props: {
    data: {
      type: Object
    }
  },
  data () {
    return {
      tableConfig: [
        {
          label: this.$t("security.windowArea"),
          prop: "configname",
          input: "input",
        },
        {
          label: this.$t("security.onlyRead"),
          prop: "lists",
          input: "select",
          checkbox: true,
          options: [
            { code: "1", description: this.$t("code.yes") },
            { code: "0", description: this.$t("code.no") }
          ]
        },
        {
          label: this.$t("security.edit"),
          prop: "edit",
          input: "select",
          checkbox: true,
          options: [
            { code: "1", description: this.$t("code.yes")},
            { code: "0", description: this.$t("code.no") }
          ]
        }
      ],
      tableData: [],
      page: 1,
      pageSize: 10,
      total: 10,
      searhData: {}
    }
  },
  methods: {
    async checked (event, data, prop) {
      let type = prop.toUpperCase();
      if (type.indexOf('LISTS') !== -1) type = type.substring(0, 4);
      let obj = [
        {
          ispermission: event ? 1 : 0,
          roleid: data.roleid,
          id: data.id,
          type: type
        }
      ]
      try {
        let res = await this.$api.post(`/permission/update`, obj);
        
          this.$message.success(res.returnMgr);
        
      } catch (e) {
        this.$message.error(e);
      }
    },
    //获取table数据
    async getTableData (page, data) {
      try {
        let res = await this.$api.post(`/permission/${this.data.argument.id}/${page}`, data);
        
          this.loading = false;
          this.tableData = res.page.list;
          this.page = res.page.curpage;
          this.pageSize = res.page.pageSize;
          this.total = res.page.total;
        
      } catch (e) {
        this.$message.error(e);
      }
    },
    //搜索值
    setSearhData (data, up) {
      if (!up) {
        this.searhData = data;
      } else {
        this.searhData = data;
        this.getTableData(1, this.searhData);
      }
    },
    //选中的数据
    setSelectData (data) {
      this.$parent.setSelectData(data)
    },
  },
  mounted () {
    this.getTableData(1, {})
  },
  components: {
    'v-table': table
  }
}
</script>

<style scoped>
</style>
